package com.longka.controller;

import com.longka.bean.Book;
import com.longka.service.BooksService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by Administrator on 2017/3/6.
 */
@Controller
@RequestMapping("/books")
public class BookInfoController {

    @Autowired
    BooksService booksService;

    @RequestMapping("/query")
    public String queryAll(HttpServletRequest request) {
        List<Book> bookList = booksService.queryAll();
        request.setAttribute("model", bookList);
        return "index";
    }


    @RequestMapping("/delete")
    @ResponseBody
    public int delete(int bookId) {
        return booksService.delete(bookId);
    }

    @RequestMapping("/add")
    public String add(String bookname, String author, String publishTime, int grade) {
        booksService.add(bookname, author, publishTime, grade);
        return "redirect:/books/query";
    }
}
